package com.jams.rbac.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.rbac.api.entity.Dict;
import com.jams.rbac.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 字典表
 *
 * @author linxb
 * @date 2020-01-07 19:23:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dict")
@Api(value = "dict", tags = "字典表管理")
public class DictController {

    private final  DictService dictService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dict 字典表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getDictPage(Page page, Dict dict) {
        return JamsResponse.ok(dictService.page(page, Wrappers.query(dict)));
    }

    /**
     * 列表查询
     * @param dict 字典表
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public JamsResponse getDictList(Dict dict) {
        return JamsResponse.ok(dictService.list(Wrappers.query(dict)));
    }

    /**
     * 通过id查询字典表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public JamsResponse getById(@PathVariable("id") Long id) {
        return JamsResponse.ok(dictService.getById(id));
    }

    /**
     * 新增字典表
     * @param dict 字典表
     * @return JamsResponse
     */
    @ApiOperation(value = "新增字典表", notes = "新增字典表")
    @PostMapping
    public JamsResponse save(@RequestBody Dict dict) {
        return JamsResponse.ok(dictService.save(dict));
    }

    /**
     * 修改字典表
     * @param dict 字典表
     * @return JamsResponse
     */
    @ApiOperation(value = "修改字典表", notes = "修改字典表")
    @PutMapping
    public JamsResponse updateById(@RequestBody Dict dict) {
        return JamsResponse.ok(dictService.updateById(dict));
    }

    /**
     * 通过id删除字典表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除字典表", notes = "通过id删除字典表")
    @DeleteMapping("/{id}")
    public JamsResponse removeById(@PathVariable Long id) {
        return JamsResponse.ok(dictService.removeById(id));
    }

}
